<template>
    <div>
        <div id="loginBox">
            <h1>登录</h1>
            <input type="text" placeholder="请输入用户名" v-model="name">
            <input type="password" placeholder="请输入密码" v-model="pwd">
            <button @click="login">LOGIN</button>
        </div>
    </div>
</template>
<script>
export default {
  data(){
      return {
          name:'',
          pwd:''
      }
  },
  methods:{
      login:function(){
          if(this.name == ''||this.pwd==''){
              alert('请输入用户名或密码');
              return;
          }

        var params = new URLSearchParams();
        params.append('name', this.name);
        params.append('pwd', this.pwd);

        this.$http.post('http://'+this.IP+'/api/login.php',params)
        .then((res)=>{
            console.log(res)
            if(res.data['code'] == 20000){
                sessionStorage.setItem('loginkey',res.data[0]['loginkey']);
                sessionStorage.setItem('name',res.data[0]['user']);
                sessionStorage.setItem('type',res.data[0]['type']);
                this.$router.push('/');
            }else{
                alert(res.data['msg'])
            }
        })
      }
  }
}
</script>
<style scoped>
    #loginBox{
        max-width: 1080px;
        height: 500px;
        margin: 0 auto;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center
    }
    input{
        width: 30%;
        height: 30px;
        margin-bottom: 10px
    }
    button{
        width: 10%;
        height: 60px;
        margin-top: 20px;
        font-size: 20px
    }
</style>
